package org.exes;

import java.io.ByteArrayOutputStream;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.zip.GZIPInputStream;
import java.util.zip.GZIPOutputStream;

public class FlujosEntradaSalidaAvanzado {
     public static void main(String[] args) throws FileNotFoundException, IOException {
        OutputStream fos = new FileOutputStream("salida2.bin");
        
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        GZIPOutputStream os = new GZIPOutputStream(baos);
        
        for (int i = 0; i < 100000; i++) {
             os.write('s');
        }
        os.flush();
        os.finish();
        fos.write(baos.toByteArray());
        fos.flush();
        fos.close();
        
        os.close();
        
        InputStream is = new GZIPInputStream(new FileInputStream("salida2.bin"));
        while(is.available()>0){
            System.out.print((char)is.read());
        }        
     }

}
